<?php
/**
 * Each engineer has a duty to keep the code elegant
 * Created by wolffy.
 * Author @wolffy<13750088090@sina.cn>
 * Date: 2018/8/15
 * Time: 14:47
 */
namespace App\Http\Middleware;

use App\Handlers\ApiResponse;
use Closure;
use Illuminate\Support\Facades\Auth;

class IdentityAuthMiddleware {

    use ApiResponse;

    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next) {
        $apiDebug = config('app.api_debug');
        if ($apiDebug) {
            return $this->responseJson(520);
        }
        if (!Auth::guard('api')->check()) {
            return $this->responseJson(403);
        }
        $user = Auth::guard('api')->user();
        if (0 == $user->is_truename_auth) {
            return $this->responseJson(10106);//请完成实名认证
        }
        return $next($request);
    }
}